const _ = require('lodash');

const ActionHelper = {
  game_type: {
    paopai: 'paopai',
    im: 'im',
  },

  user_action: {
    register: '注册',
    open_app: '打开app',
    active_time: '活跃时间',
    play_game: '进行游戏',
    cost_cards: '消耗房卡',
    online_users: '在线人数', // 服务器发过来
    game_over: '牌局结束', // 服务器发送过来
  },

  arena_action: {
    arena_room_over: '竞技场房间游戏结束',
    arena_season_over: '竞技场赛季结束',
    arena_season_reward: '竞技场赛季结束奖励',
  },

  payment_action: {
    recharge: '充值',
    withdraw: '提现',
    create_group: '新建群组',
    group_red_packet: '群红包',
    group_gathering_money: '群收款',
  },

  isRegister: action => action === ActionHelper.user_action.register,

  isOpenApp: action => action === ActionHelper.user_action.open_app,

  isActiveTime: action => action === ActionHelper.user_action.active_time,

  isPlayGame: action => action === ActionHelper.user_action.play_game,

  isCostCards: action => action === ActionHelper.user_action.cost_cards,

  isOnlineUsers: action => action === ActionHelper.user_action.online_users,

  isGameOver: action => action === ActionHelper.user_action.game_over,

  isRecharge: action => action === ActionHelper.payment_action.recharge,

  isWithdraw: action => action === ActionHelper.payment_action.withdraw,

  isArenaRoomOver: action => action == ActionHelper.arena_action.arena_room_over,

  isArenaSeasonReward: action => action == ActionHelper.arena_action.arena_season_reward,

  getIMActions: () => _.values(_.pick(ActionHelper.user_action, ['register', 'open_app', 'active_time'])),

  getPaopaiActions: () => [
    ..._.values(
      _.pick(ActionHelper.user_action, ['register', 'open_app', 'play_game', 'cost_cards', 'online_users', 'game_over'])
    ),
    ..._.values(ActionHelper.arena_action),
  ],

  getPaymentActions: () => _.values(ActionHelper.payment_action),

  getOpenAppAction: () => ActionHelper.user_action.open_app,

  getRechargeAction: () => ActionHelper.user_action.recharge,

  getWithdrawAction: () => ActionHelper.user_action.withdraw,

  isValidUserAction: function(action, game_type) {
    let actions = [];
    if (game_type == ActionHelper.game_type.paopai) actions = ActionHelper.getPaopaiActions();
    if (game_type == ActionHelper.game_type.im) actions = ActionHelper.getIMActions();
    return ActionHelper.isValidAction(actions, action);
  },

  isValidPaymentAction: function(action) {
    const actions = ActionHelper.getPaymentActions();
    return ActionHelper.isValidAction(actions, action);
  },

  isValidAction: (actions, action) => actions.includes(action),
};

module.exports = ActionHelper;
